package kis.io.leadingInExcel;

import java.io.File;
import java.io.IOException;

import jxl.Cell;
import jxl.CellType;
import jxl.DateCell;
import jxl.NumberCell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 操作excel类
 * @author bacoo
 *
 */
public class OperationExcel {
	final Logger logger = LoggerFactory.getLogger(OperationExcel.class);
	/**
	 * 读取excel
	 */
	public void readExcel(String path)
	{
		try
		{
			File file = new File(path);
			Workbook book = Workbook.getWorkbook(file);
			Sheet sheet = book.getSheet(0);//行
			for (int sheetNum = 0; sheetNum < sheet.getRows(); sheetNum++)
			{
				Cell[] cell = sheet.getRow(sheetNum);//列
				for (int cellNum = 0; cellNum < cell.length; cellNum++)
				{
					String data = cell[cellNum].getContents();
					if(cell[cellNum].getType()==CellType.DATE){
						DateCell dc = (DateCell) cell[cellNum];
						//TODO data format
					}else if(cell[cellNum].getType()==CellType.NUMBER ||cell[cellNum].getType()==CellType.NUMBER_FORMULA)
					{
						 NumberCell nc=(NumberCell)cell[cellNum];  
					     data=""+nc.getValue();  
					}
				}
			}
			book.close();
		} catch (BiffException e)
		{
			System.out.println(e);
			logger.error("读取excel文件出错");
		} catch (IOException e)
		{
			logger.error("读取excel文件出错");
		}
	}
}
